package com.hualan.sfzyproject.controller;


import com.hualan.sfzyproject.domain.ConsultationAppointment;
import com.hualan.sfzyproject.service.ConsultationAppointmentService;
import com.hualan.sfzyproject.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/consultationAppointment")
public class ConsultationAppointmentController {
    @Autowired
    private ConsultationAppointmentService consultationAppointmentService;

    @RequestMapping("/selectByUserId")
    public R selectByUserId(int userId, int pageNum, int pageSize) {
        List<ConsultationAppointment> list = consultationAppointmentService.selectByUserId(userId, pageNum, pageSize);
        if (list == null) {
            return R.error2("没有更多数据");
        } else {
            return R.ok(list);
        }
    }

    @PutMapping("/updateStatusByAppointmentId")
    public R updateStatusByAppointmentId(@RequestParam("appointmentId") int appointmentId,@RequestParam("status") int status) {
        int i = consultationAppointmentService.updateStatusByAppointmentId(appointmentId, status);
        if (i == 1) {
            return R.success("修改成功");
        } else {
            return R.error2("修改失败");
        }
    }

    @RequestMapping("/insert")
    public R insert(@RequestBody ConsultationAppointment consultationAppointment) {
        System.out.println(consultationAppointment);
        int i = consultationAppointmentService.insert(consultationAppointment);
        if (i == 1) {
            return R.success("插入成功");
        } else {
            return R.error2("插入失败");
        }
    }



    @GetMapping("/selectByConsultantId")
    public R selectByConsultantId(int consultantId) {
        List<ConsultationAppointment> list = consultationAppointmentService.selectByConsultantId(consultantId);
        if (list == null) {
            return R.error2("没有更多数据");
        } else {
            return R.ok(list);
        }
    }
}
